package com.easylinkin.linkappapi.airconditioner.controller;

import com.easylinkin.linkappapi.airconditioner.entity.AirHostDevice;
import com.easylinkin.linkappapi.airconditioner.entity.AirconditionDeviceRecord;
import com.easylinkin.linkappapi.airconditioner.service.AirconditionDeviceRecordService;
import com.easylinkin.linkappapi.common.model.RequestModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: linkapp-group
 * @description: 分户计量
 * @author: chenkaixuan
 * @create: 2021-05-10 17:01
 */
@RestController
@RequestMapping("/airconditioner/airdeviceRecord")
public class AirconditionDeviceRecordController {
    @Autowired
    AirconditionDeviceRecordService airconditionDeviceRecordService;

    /***
     * 分户计量
     * @param requestModel
     * @return
     */
    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<AirconditionDeviceRecord> requestModel){
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        return RestBuilders.successBuilder(airconditionDeviceRecordService.selectGroupByStatistics(requestModel.getPage(),requestModel.getCustomQueryParams())).build();
    }

    /***
     * 导出
     * @param requestModel
     * @return
     */
    @PostMapping("export")
    public void export(@RequestBody AirconditionDeviceRecord requestModel, HttpServletRequest request, HttpServletResponse response){
        airconditionDeviceRecordService.exportData(requestModel,request,response);
    }
}
